package com.lam.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lam.common.utils.StringUtils;
import com.lam.mall.entity.Delivery;
import com.lam.mall.mapper.DeliveryMapper;
import com.lam.mall.param.DeliveryParam;
import com.lam.mall.service.DeliveryService;

/**
 * 物流公司Service业务层处理
 * 
 * @author admin
 * @date 2023-04-27
 */
@Service
public class DeliveryServiceImpl  implements DeliveryService {

    @Autowired
    private DeliveryMapper deliveryMapper;

    /**
     * 查询物流公司
     * 
     * @param id ID
     * @return 单个对象
     */
    @Override
    @Transactional(readOnly = true)
    public Delivery selectById(String id) {

        return deliveryMapper.selectById(id);
    }

    /**
     * 查询物流公司列表
     * 
     * @param param
     * @return 
     */
    @Override
    @Transactional(readOnly = true)
    public List<Delivery> selectList(DeliveryParam param) {
    
        QueryWrapper<Delivery> queryWrapper = new QueryWrapper<>();

        //关键字查询
        if(StringUtils.isNotBlank(param.getKeywords())) {
            queryWrapper.and(wr->{
                wr.or().like("dvy_name", param.getKeywords());
            });
        }
        
        queryWrapper.like(StringUtils.isNotBlank(param.getDvyNameKey()), "dvy_name", param.getDvyNameKey());
        queryWrapper.eq(StringUtils.isNotBlank(param.getDvyName()), "dvy_name", param.getDvyName());

        return deliveryMapper.selectList(queryWrapper);
    }

    /**
     * 新增物流公司
     * 
     * @param delivery 
     * @return 
     */
    @Override
    @Transactional
    public int insert(Delivery delivery) {
    
        return deliveryMapper.insert(delivery);
    }

    /**
     * 修改物流公司
     * 
     * @param delivery 
     * @return 
     */
    @Override
    @Transactional
    public int update(Delivery delivery) {
    
        return deliveryMapper.updateById(delivery);
    }

    /**
     * 删除物流公司信息
     * 
     * @param idStr ID，多个用逗号分隔
     * @return 
     */
    @Override
    @Transactional
    public int deleteById(String idStr) {
    
        if(StringUtils.isBlank(idStr)) {
            return 0;
        }
        return deliveryMapper.deleteBatchIds(StringUtils.str2List(idStr));
    }
    
    
}
